package com.UI
{
	import com.*;
	import com.Home.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameClickMapChar extends JFrame
	{
		//members define
		private var panelHead:JPanel;
		private var labelName:JLabel;
		private var labelLevel:JLabel;
		private var panel7:JPanel;
		private var btn_trade:JButton;
		private var btn_team:JButton;
		private var btn_friend:JButton;
		private var btn_chat:JButton;
		private var btn_compare:JButton;
		private var btn_pk:JButton;
		private var btn_bwatch:JButton;
		private var btn_enslave:JButton;
		private var btn_watch:JButton;
		private var btn_home:JButton;
		
		
		//-----------------------------------
		private var btn_close:JButton;
		private var _destCharId:uint;
		private var _obj:ObjectCharPlayer
		public function FrameClickMapChar()
		{
			setResizable(true);
			setClosable(false);
			setDragable(false);
			setBackgroundDecorator(null);
			//this.getTitleBar().setTitleEnabled(false);
			//this.getTitleBar().setMinimizeHeight(0);
			setBorder(new EmptyBorder());
			
			//component creation
			setSize(new IntDimension(168, 203));
			setPreferredSize(new IntDimension(168, 203));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panelHead = new JPanel();
			panelHead.setLocation(new IntPoint(0, -33));
			panelHead.setSize(new IntDimension(66, 66));
			panelHead.setPreferredSize(new IntDimension(66, 66));
			
			labelName = new JLabel();
			labelName.setLocation(new IntPoint(70, 4));
			labelName.setSize(new IntDimension(86, 14));
			labelName.setPreferredSize(new IntDimension(86, 14));
			labelName.setText("陶陶陶");
			labelName.setHorizontalAlignment(AsWingConstants.CENTER);
			
			labelLevel = new JLabel();
			labelLevel.setLocation(new IntPoint(63, 23));
			labelLevel.setSize(new IntDimension(86, 14));
			labelLevel.setPreferredSize(new IntDimension(86, 14));
			labelLevel.setText("Lv.28");
			
			panel7 = new JPanel();
			panel7.setLocation(new IntPoint(45, 41));
			panel7.setSize(new IntDimension(112, 125));
			panel7.setPreferredSize(new IntDimension(112, 125));
			var layout1:GridLayout = new GridLayout();
			layout1.setRows(5);
			layout1.setColumns(2);
			layout1.setHgap(0);
			layout1.setVgap(0);
			panel7.setLayout(layout1);
			
			btn_trade = new JButton();
			btn_trade.setLocation(new IntPoint(0, 0));
			btn_trade.setSize(new IntDimension(49, 29));
			btn_trade.setPreferredSize(new IntDimension(49, 29));
			btn_trade.setText("label");
			
			btn_team = new JButton();
			btn_team.setLocation(new IntPoint(56, 0));
			btn_team.setSize(new IntDimension(49, 29));
			btn_team.setPreferredSize(new IntDimension(49, 29));
			btn_team.setText("label");
			
			btn_friend = new JButton();
			btn_friend.setLocation(new IntPoint(0, 25));
			btn_friend.setSize(new IntDimension(49, 24));
			btn_friend.setPreferredSize(new IntDimension(49, 29));
			btn_friend.setText("label");
			
			btn_chat = new JButton();
			btn_chat.setLocation(new IntPoint(56, 25));
			btn_chat.setSize(new IntDimension(49, 24));
			btn_chat.setPreferredSize(new IntDimension(49, 29));
			btn_chat.setText("label");
			
			btn_compare = new JButton();
			btn_compare.setLocation(new IntPoint(0, 50));
			btn_compare.setSize(new IntDimension(56, 25));
			btn_compare.setText("label");
			
			btn_pk = new JButton();
			btn_pk.setLocation(new IntPoint(0, 0));
			btn_pk.setSize(new IntDimension(50, 17));
			btn_pk.setPreferredSize(new IntDimension(56, 25));
			btn_pk.setText("label");
			
			btn_bwatch = new JButton();
			btn_bwatch.setLocation(new IntPoint(56, 75));
			btn_bwatch.setSize(new IntDimension(56, 25));
			btn_bwatch.setText("label");
			
			btn_enslave = new JButton();
			btn_enslave.setLocation(new IntPoint(56, 75));
			btn_enslave.setSize(new IntDimension(56, 25));
			btn_enslave.setText("label");
			
			btn_watch = new JButton();
			btn_watch.setLocation(new IntPoint(0, 100));
			btn_watch.setSize(new IntDimension(56, 25));
			btn_watch.setText("label");
			
			btn_home = new JButton();
			btn_home.setLocation(new IntPoint(65, 62));
			btn_home.setSize(new IntDimension(63, 29));
			btn_home.setPreferredSize(new IntDimension(49, 29));
			btn_home.setText("label");
			
			//component layoution
			getContentPane().append(panelHead);
			getContentPane().append(labelName);
			getContentPane().append(labelLevel);
			getContentPane().append(panel7);
			
			panel7.append(btn_trade);
			panel7.append(btn_team);
			panel7.append(btn_friend);
			panel7.append(btn_chat);
			panel7.append(btn_compare);
			panel7.append(btn_pk);
			panel7.append(btn_bwatch);
			panel7.append(btn_enslave);
			panel7.append(btn_watch);
			panel7.append(btn_home);
			
			
			//-----------------------------------------------
			getContentPane().revalidate();
			pack();
			setResizable(false);
			//setSizeWH(width,height);
			setLocationXY((Engine.W - width)/2,(Engine.H - height)/2);
			//setLocationXY(x,y);
			btn_close = new JButton();
			btn_close.setLocation(new IntPoint(198, -5));
			btn_close.setSize(new IntDimension(27, 27));
			btn_close.setPreferredSize(new IntDimension(27, 27));
			getTitleBar().setCloseButton(btn_close);
			getTitleBar().setMinimizeHeight(32);
			setImages();
			this.setClipMasked(false);
			this.getContentPane().setClipMasked(false);
		}
		public function setImages():void
		{
			var img_background:DisplayObject = Client.getUIElement("img_click_bg") as DisplayObject
			setSizeWH(img_background.width,img_background.height);
			setLocationXY((Engine.W - img_background.width)/2,(Engine.H - img_background.height)/2);
			setBackgroundDecorator(new AssetBackground(img_background));
			

			panelHead.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_head") as DisplayObject));
			
			btn_team.addActionListener(onBtnTeam);
			btn_trade.addActionListener(onBtnTrade);
			btn_compare.addActionListener(onBtnCompare);
			btn_pk.addActionListener(onBtnPK);
			btn_enslave.addActionListener(onBtnEnslave);
			btn_friend.addActionListener(onBtnFriend);
			btn_chat.addActionListener(onBtnChat);
			btn_bwatch.addActionListener(onBtnBattleWatch);
			btn_watch.addActionListener(onBtnWatch);
			btn_home.addActionListener(onBtnHome);
			
			btn_team.wrapSimpleButton(Client.getUIElement("btn_click_team") as SimpleButton);
			btn_trade.wrapSimpleButton(Client.getUIElement("btn_click_trade") as SimpleButton);
			btn_pk.wrapSimpleButton(Client.getUIElement("btn_click_pk") as SimpleButton);
			btn_friend.wrapSimpleButton(Client.getUIElement("btn_click_friend") as SimpleButton);
			btn_chat.wrapSimpleButton(Client.getUIElement("btn_click_chat") as SimpleButton);
			
			btn_compare.wrapSimpleButton(Client.getUIElement("btn_click_compare") as SimpleButton);
			btn_bwatch.wrapSimpleButton(Client.getUIElement("btn_click_wbattle") as SimpleButton);
			btn_enslave.wrapSimpleButton(Client.getUIElement("btn_click_enslave") as SimpleButton);
			btn_watch.wrapSimpleButton(Client.getUIElement("btn_click_watch") as SimpleButton);
			btn_home.wrapSimpleButton(Client.getUIElement("btn_click_home") as SimpleButton);
			
			btn_team.setText("");
			btn_trade.setText("");
			btn_pk.setText("");
			btn_friend.setText("");
			btn_chat.setText("");
			
			btn_compare.setText("");
			btn_bwatch.setText("");
			btn_enslave.setText("");
			btn_watch.setText("");
			btn_home.setText("");
			
			/*labelName.setText(_obj.getName());
			labelLevel.setText('Lv.'+_obj.getLevel().toString());
			_destCharId = _obj.charId;
			
			btn_team.setEnabled(_destCharId != CharInfo.charId);
			btn_trade.setEnabled(_destCharId != CharInfo.charId);
			btn_pk.setEnabled(_destCharId != CharInfo.charId);
			btn_friend.setEnabled(_destCharId != CharInfo.charId);
			btn_chat.setEnabled(_destCharId != CharInfo.charId);*/
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 13, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelName.setFont(font);
			labelName.setForeground(ASColor.WHITE);
			labelName.setTextFilters(new Array(filter));
			
			font = new ASFont("宋体", 12, false, false, false, false);
			labelLevel.setFont(font);
			labelLevel.setForeground(ASColor.WHITE);
			labelLevel.setTextFilters(new Array(filter));
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			//addEventListener(FrameEvent.FRAME_CLOSING,onFrameClosing);
		}
		public static function update():void
		{
			_frame.labelName.setText(_frame._obj.getName());
			_frame.labelLevel.setText('Lv.'+_frame._obj.getLevel().toString());
			_frame._destCharId = _frame._obj.charId;
			
			//if(!_obj.isInTeam())
			//	Client.getInstance().sendPacketLogic(200,[_destCharId]);
			//else if(CharInfo.objSelf.isInTeam())
				
			//if(!_obj.isInTeam() && (!CharInfo.objSelf.isInTeam() || CharInfo.objSelf.isTeamLeader()))
			//	Client.getInstance().sendPacketLogic(200,[_destCharId]);
			//else if(!CharInfo.objSelf.isInTeam() && (!_obj.isInTeam() || _obj.isTeamLeader()))
			//	Client.getInstance().sendPacketLogic(205,[_destCharId]);
			_frame.btn_team.setEnabled((!_frame._obj.isInTeam() && (!CharInfo.objSelf.isInTeam() || CharInfo.objSelf.isTeamLeader()))
				|| (!CharInfo.objSelf.isInTeam() && (!_frame._obj.isInTeam() || _frame._obj.isTeamLeader())));
			
			_frame.btn_team.setEnabled((!_frame._obj.isInTeam()|| !CharInfo.objSelf.isInTeam()) && _frame._destCharId != CharInfo.charId);
			_frame.btn_trade.setEnabled(_frame._destCharId != CharInfo.charId);
			_frame.btn_pk.setEnabled(_frame._destCharId != CharInfo.charId);
			_frame.btn_friend.setEnabled(_frame._destCharId != CharInfo.charId);
			_frame.btn_chat.setEnabled(_frame._destCharId != CharInfo.charId);
			_frame.btn_bwatch.setEnabled(_frame._destCharId != CharInfo.charId);
			_frame.btn_compare.setEnabled(_frame._destCharId != CharInfo.charId);
			_frame.btn_enslave.setEnabled(_frame._destCharId != CharInfo.charId);
		}
		public static var _frame:FrameClickMapChar = null;
		public static function show(obj:ObjectCharPlayer):void
		{
			if(_frame == null)
			{
				_frame = new FrameClickMapChar();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);

			_frame._obj = obj;
			update();
			_frame.setLocationXY((Engine.W - _frame.width)/2,(Engine.H - _frame.height)/2);
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
			if(_frame != null)
				_frame._obj = null;
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		
		private function onBtnClose(e:Event):void
		{
			this.closeReleased();
		}
		
		private function onBtnTeam(e:Event):void
		{
			if(_destCharId == CharInfo.charId)
				return;

			this.closeReleased();
			//PanelMain.showInfoTimeLimit("邀请组队请求发送成功!");
			if(!_obj.isInTeam() && (!CharInfo.objSelf.isInTeam() || CharInfo.objSelf.isTeamLeader()))
				Client.getInstance().sendPacketLogic(200,[_destCharId]);
			else if(!CharInfo.objSelf.isInTeam() && (!_obj.isInTeam() || _obj.isTeamLeader()))
				Client.getInstance().sendPacketLogic(205,[_destCharId]);
		}
		
		private function onBtnTrade(e:Event):void
		{
			if(_destCharId == CharInfo.charId)
				return;
			this.closeReleased();
			Client.getInstance().sendPacketLogic(800,[_destCharId]);
		}
		
		private function onBtnHome(e:Event):void
		{
			this.closeReleased();
			if(_destCharId == CharInfo.charId)
			{
				//var mc_effect:MovieClip = Client.getEffectElement("mc_effect_" + 2000000) as MovieClip;
				//if(mc_effect == null)
				//	return;
				//CharInfo.objSelf.addEffect(2000000,mc_effect);
				FrameMining.show();
				//FrameBattleEndLose.show();
				//FrameHomeBuilding9Equip.show(null);
				return;
			}
			Home.visitHome(_destCharId);
		}
		
		private function onBtnCompare(e:Event):void
		{
			if(_destCharId == CharInfo.charId)
				return;
			//Client.getInstance().sendPacketLogic(300,[int(SceneBattle.BATTLE_TYPE_PVP_COMPARE),_destCharId]);
			Client.getInstance().sendPacketLogic(308,[_destCharId]);
			this.closeReleased();
		}
		private function onBtnPK(e:Event):void
		{
			if(_destCharId == CharInfo.charId)
				return;
			Client.getInstance().sendPacketLogic(300,[int(SceneBattle.BATTLE_TYPE_PVP_PK),_destCharId]);
			this.closeReleased();
		}
		private function onBtnEnslave(e:Event):void
		{
			if(_destCharId == CharInfo.charId)
				return;
			Client.getInstance().sendPacketLogic(300,[int(SceneBattle.BATTLE_TYPE_PVP_ENSLAVE),_destCharId]);
			this.closeReleased();
		}
		
		private function onBtnFriend(e:Event):void
		{
			Client.getInstance().sendPacketLogic(601,[_destCharId]);
			this.closeReleased();
		}
		private function onBtnBattleWatch(e:Event):void
		{
			Client.getInstance().sendPacketLogic(310,[_destCharId]);
			this.closeReleased();
		}
		private function onBtnWatch(e:Event):void
		{
			Client.getInstance().sendPacketLogic(605,[int(_destCharId)]);
			this.closeReleased();
		}
		private function onBtnChat(e:Event):void
		{
			if(_obj.userObject == null)
				return;
			FrameFriendChat.show(_obj.userObject);
			//FrameFriendChat.show({m_nCharId:_destCharId,m_szCharName:_obj.getName(),m_nLevel:_obj.getLevel(),m_nRace:_obj.m_nRace,m_nGender:_obj.userObject.m_nGender});
			this.closeReleased();
		}
	}
}